package me.zzde.wallpaper.utils;

import android.util.Log;


import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;


import org.json.JSONObject;

import java.io.IOException;

import me.zzde.wallpaper.model.UserWallpaper;

public class ApiServer {
    private OkHttpClient okHttpClient = new OkHttpClient();

    String baseUrl = "http://172.20.10.4:8080/mobile";


    public void getIndex(){
        Request request = new Request.Builder().get().url(baseUrl + '/').build();

        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
                Log.i("ApiServer", "onFailure: " + "error");
            }

            @Override
            public void onResponse(Response response) throws IOException {
                if (response.isSuccessful()) {
                    try {
                        final String result = response.body().string();
                        JSONObject obj = new JSONObject(result);
                    } catch (Exception e) {
                        Log.e("ApiServer", "Exception = " + e);
                    }
                }else{
                    Log.i("ApiServer", "onResponse: " + "error");
                }
            }
        });
    }
}
